using System.Collections.Generic;
using System.Linq;
using System.Net;

namespace LDNS.SDK.Commands.Models
{
    /// <summary>
    /// 设置配置项命令类
    /// 作者: huobing
    /// </summary>
    public sealed class SetConfigCommand : BaseCommand<DefaultCommandResult>
    {
        /// <summary>
        /// 命令名称
        /// </summary>
        public const string NAME = "SET_CONFIG";
        
        /// <summary>
        /// 获取命令名称
        /// </summary>
        public override string Name => NAME;
        
        /// <summary>
        /// 获取命令格式
        /// </summary>
        public override string Format => "SET_CONFIG key=value ...";
        
        /// <summary>
        /// 获取命令描述
        /// </summary>
        public override string Description => "设置配置项";
        
        /// <summary>
        /// 获取命令权限级别
        /// </summary>
        public override CommandPermission Permission => CommandPermission.Admin;
        
        /// <summary>
        /// 验证命令参数
        /// </summary>
        /// <param name="args">命令参数数组</param>
        /// <param name="error">错误信息输出</param>
        /// <returns>验证是否通过</returns>
        public override bool Validate(string[] args, out string error)
        {
            error = string.Empty;
            if (args.Length < 1) { error = "SET_CONFIG 至少需要一个 key=value"; return false; }
            if (args.Any(a => !a.Contains('='))) { error = "SET_CONFIG 参数需为 key=value 格式"; return false; }
            return true;
        }
    }
}